#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //connect(ui->btnHello, &QPushButton::clicked, this, &MainWindow::sayHello);
    connect(ui->btnHello, &QPushButton::clicked, ui->btnHalo, &QPushButton::clicked);
    connect(ui->btnHalo, &QPushButton::clicked, this, &MainWindow::sayHalo);
    connect (ui->btnBonjour, &QPushButton::clicked, [this](){ // (CONFIG += c++11)this way, there is no need to declare a slot and define and connect it
        //ui->teDisp->append (QString("Bonjour"));
        emit ui->btnHello->clicked();
    });

    // disconnect all connections between a specific signal sender and a specific receiver
    // disconnect(ui->btnHello, NULL, this, NULL);
    // disconnect all the signals in btnHello
    // disconnect(ui->btnHello, NULL, NULL, NULL);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::sayHello ()
{
    ui->teDisp->append(QString("hello"));
}

void MainWindow::sayHalo ()
{
    ui->teDisp->append(QString("halo"));
    disconnect (ui->btnHello, &QPushButton::clicked, this, &MainWindow::sayHello);
}
